home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!netnews
- From: jlilley@ix.netcom.com (John Lilley)
- Newsgroups: comp.lang.c++
- Subject: Re: Newbie requires help!
- Date: 18 Mar 1996 17:18:05 GMT
- Organization: Netcom
- Distribution: world
- Message-ID: <4ik5sd$14k@reader2.ix.netcom.com>
- References: <AMeOMBA0erSxEwc0@waichung.demon.co.uk>
- NNTP-Posting-Host: den-co8-14.ix.netcom.com
- Mime-Version: 1.0
- Content-Type: Text/Plain; charset=US-ASCII
- X-NETCOM-Date: Mon Mar 18 9:18:05 AM PST 1996
- X-Newsreader: WinVN 0.99.7
-
- In article <AMeOMBA0erSxEwc0@waichung.demon.co.uk>, kyn@waichung.demon.co.uk says...
- >
- >I require help in constructing a binary search tree in c++, as i am
- >relatively new to the language i am not sure how to go about
- >implementing it.
- > Do i construct a class called btree or do i use the following:-
- >
- > struct node
- > {
- > data d;
- > struct node *left;
- > struct node *right;
- > }
-
- Well, the answer for this would be too much like an entire C++ book, so
- first -- go buy some C++ books, like:
- Lippmann "C++ Primer"
- Meyers "Effective C++"
- Cargill "C++ Programming Style"
-
- The above notwithstanding, you want to make the procedures in your pascal
- program members of your "Node" class, assuming that "Node" corresponds
- to what you are calling "Subtree" in Pascal. I'm also adding some code
- for inialization and such, that you'll have to dig around for in a C++ book:
-
- class data {/* whatever is in data */};
-
- class Node
- {
- public:
- Node(const data& d_) d(d_) {}
- void SearchAndInsert(const data& newDatum)
- {
- // Presumes that class data holds both key and data.
- // Note that there is no "subtree" argument because the
- // method implicitly operates on the "Node" object for
- // which is was invoked.
- }
- void PrintTree();
- private:
- data d;
- Node *left;
- Node *right;
- }
-
- void BuildTree()
- {
- // This is a function because it is not an operation on Node
- }
-
-
- Its at least a start...
-
- john lilley
-
-